package prepared;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class insertdemo01 {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/yzy_db";
        String username = "root";
        String pwd = "123456";
        Connection con = DriverManager.getConnection(url, username, pwd);
        String sql = "INSERT INTO t_yzy(id,name,age,sex) values(?,?,?,?)";
        PreparedStatement pst = con.prepareStatement(sql);
        pst.setInt(1, 10);
        pst.setString(2,"丽丽");
        pst.setString(3,"18");
        pst.setString(4,"女");
        int count = pst.executeUpdate();
        if (count > 0) {
            System.out.println("添加成功");
        } else {
            System.out.println("添加失败");
        }
        pst.close();
        con.close();
    }
    }

